package com.company.cloud.point.client;

import com.company.cloud.common.asserts.ValidatorUtils;
import com.company.cloud.common.bean.BaseClientResult;
import com.company.cloud.common.bean.LoginSimpleUserInfo;
import com.company.cloud.point.modules.api.request.PointEventParam;
import com.company.cloud.point.modules.api.service.PointRemoteService;
import com.company.cloud.point.modules.mgr.service.PointRuleConfigMgrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Service
public class PointRemoteServiceImpl implements PointRemoteService {

    @Autowired
    private PointRuleConfigMgrService pointRuleConfigMgrService;

    @Override
    public BaseClientResult<String> pointEventProcess(PointEventParam request) {
        try {
            ValidatorUtils.validate(request);
            LoginSimpleUserInfo userInfo=this.getLoginSimpleUser(request.getOpUserId(),request.getOpIp());
            pointRuleConfigMgrService.pointEventProcess(request,userInfo);
            return BaseClientResult.success();
        }catch (Exception e){
            return BaseClientResult.error(e);
        }
    }

    private LoginSimpleUserInfo getLoginSimpleUser(Integer userId,String ip){
        LoginSimpleUserInfo userInfo=new LoginSimpleUserInfo();
        userInfo.setId(userId);
        userInfo.setIp(ip);
        return userInfo;
    }




}
